package estate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Wlodek
 */

public abstract class Estate implements Comparable <Estate>{
    

    public User getUser() {
        return null;
    }

    public void setUser(User user) {
           }
    public void dekoruj(HashMap<String,Object> hm){
    }
    public abstract int getTypOferty();

    public int compareTo(Estate e){
   
        return 1;
    }

	/* BEGIN Funkcjonalnosć komentarzy */
	
	private List<Comment> komentarze = new ArrayList<Comment>();

	public List<Comment> getKomentarze()
	{
		return this.komentarze;
	}

	public Comment addKomentarz(Comment tmp)
	{
		if (this.isCommentAcceptable(tmp))
		{
			this.komentarze.add(tmp);
	    	tmp.getUser().addKomentarz(tmp);
	    	return tmp;
		}
		return null;
	}

	public boolean isCommentAcceptable(Comment comment) {
		User user = comment.getUser();
		Iterator<Comment> iter = komentarze.iterator();
		int counter = 0;
		Comment c;
		while(iter.hasNext()) {
			c = iter.next();
			if(c.getUser().equals(user)) {
				counter++;
			}
		}
		return (counter < 3);
	}

	/* END Funkcjonalnosć komentarzy */
    
}
